using homework_2_test_first_development.Models;

namespace homework_2_test_first_development.Services;

internal static class ReceiptFormatter
{
    public static string FormatReceipt(Receipt receipt)
    {
        string[] header = { "Receipt", "-------" };

        var body = receipt.Products.Select(
            p => $"Name: {p.Name}, Amount: {p.Amount}, Price: {p.Price:F2}, Total: {p.TotalPrice:F2}");

        string[] summary = { "-------", $"Total: {receipt.Products.Sum(p => p.TotalPrice):F2}" };

        return string.Join(Environment.NewLine, header.Concat(body).Concat(summary));
    }
}
